home *** CD-ROM | disk | FTP | other *** search
- Path: news.InterGate.BC.CA!usenet
- From: (tu)
- Newsgroups: comp.lang.c++
- Subject: Re: Why C++ sucks++
- Date: Wed, 07 Feb 1996 03:12:37 GMT
- Organization: h
- Message-ID: <4f925g$i5f@carrera.intergate.bc.ca>
- References: <1996Jan29.223357.1@aspen>
- NNTP-Posting-Host: pm4s3.intergate.bc.ca
- X-Newsreader: Forte Free Agent 1.0.82
-
- ferriom@aspen wrote:
-
-
-
- >*** HIGH SCHOOL ***
-
- >100 PRINT "Hello World."
- >999 END
-
-
-
- >*** COLLEGE FRESHMAN ***
-
- > WRITE (6, 100)
- > 100 FORMAT (1X, 'Hello World.')
- > END
-
-
-
- >*** ADVANCED COLLEGE ***
-
- >PROGRAM P1(INPUT, OUTPUT);
-
- >BEGIN
- >WRITELN(OUTPUT, 'Hello World.');
- >END.
-
-
-
- >*** RECENT COLLEGE GRADUATE ***
-
- > IDENTIFICATION DIVISION.
- > PROGRAM-ID.
- > P1.
-
- > ENVIRONMENT DIVISION.
-
- > DATA DIVISION.
- > WORKING-STORAGE SECTION.
- > 01 MESSAGE-RECORD PICTURE X(12).
-
- > PROCEDURE DIVISION.
- > PROGRAM-BEGIN.
- > FIRST-PARAGRAPH.
- > MOVE 'Hello World.' TO MESSAGE-RECORD.
- > DISPLAY MESSAGE-RECORD.
- > PROGRAM-DONE.
- > STOP RUN.
-
-
-
- >*** SEASONED PROFESSIONAL ***
-
- >#include <iostream.h>
- >#include <string.h>
-
-
- >class String
- >{
- > public:
- > String();
- > String(const char *const);
- > String(const String &);
- > ~String();
- > char & operator[](unsigned short offset);
- > char operator[](unsigned short offset) const;
- > String operator+(const String&);
- > void operator+=(const String&);
- > String & operator= (const String &);
- > unsigned short GetLen()const {return itsLen; }
- > const char * GetString() const {return itsString; }
- > private:
- > String (unsigned short);
- > char * itsString;
- > unsigned short itsLen;
- >};
-
-
- >String::String()
- >{
- > itsString = new char[1];
- > itsString[0] = '\0';
- > itsLen = 0;
- >}
-
- >String::String(unsigned short len)
- >{
- > itsString = new char[len + 1];
- > for (unsigned short i = 0; i <= len; i++)
- > itsString[i] = '\0';
- > itsLen = len;
- >}
-
- >String::String(const char * const cString)
- >{
- > itsLen = strlen(cString);
- > itsString = new char[itsLen + 1];
- > for (unsigned short i = 0; i < itsLen; i++)
- > itsString[i] = cString[i];
- > itsString[itsLen] = '\0';
- >}
-
- >String::String(const String & rhs)
- >{
- > itsLen = rhs.GetLen();
- > itsString = new char[itsLen + 1];
- > for (unsigned short i = 0; i < itsLen; i++)
- > itsString[i] = rhs[i];
- > itsString[itsLen] = '\0';
- >}
-
- >String::~String()
- >{
- > delete [] itsString;
- > itsLen = 0;
- >}
-
- >String& String::operator=(const String & rhs)
- >{
- > if (this == &rhs)
- > return *this;
- > delete [] itsString;
- > itsLen = rhs.GetLen();
- > itsString = new char[itsLen + 1];
- > for (unsigned short i = 0; i < itsLen; i++)
- > itsString[i] = rhs[i];
- > itsString[itsLen] = '\0';
- > return *this;
- >}
-
- >char & String::operator[](unsigned short offset)
- >{
- > if (offset > itsLen)
- > return itsString[itsLen - 1];
- > else
- > return itsString[offset];
- >}
-
- >char String::operator[](unsigned short offset) const
- >{
- > if (offset > itsLen)
- > return itsString[itsLen - 1];
- > else
- > return itsString[offset];
- >}
-
- >String String::operator+(const String& rhs)
- >{
- > unsigned short totalLen = itsLen + rhs.GetLen();
- > String temp(totalLen);
- > for (unsigned short i = 0; i < itsLen; i++)
- > temp[i] = itsString[i];
- > for (unsigned short j = 0; j < rhs.GetLen(); j++, i++)
- > temp[i] = rhs[j];
- > temp[totalLen] = '\0';
- > return temp;
- >}
-
- >void String::operator+=(const String& rhs)
- >{
- > unsigned short rhsLen = rhs.GetLen();
- > unsigned short totalLen = itsLen + rhsLen;
- > String temp(totalLen);
- > for (unsigned short i = 0; i < itsLen; i++)
- > temp[i] = itsString[i];
- > for (unsigned short j = 0; j < rhs.GetLen(); j++, i++)
- > temp[i] = rhs[i - itsLen];
- > temp[totalLen] = '\0';
- > *this = temp;
- >}
-
-
- >main()
- >{
- > String s1("Hello");
- > String s2(" ");
- > String s3("World.");
- > String s4 = s1 + s2 + s3;
- > cout << s4.GetString() << endl;
- >}
-
-
- i don't get your point!!!
- to write Hello you could simply write
-
- #include <iostream.h>
-
- void main()
- {
- cout << "Hello" << endl;
- }
-
- What's the difference from basic, pascal, modula 2, and any other
- languages??
- DS
-
-